using System;
using System.Diagnostics;
using System.IO;

namespace TaskVision
{
	public sealed class LogError
	{

		private const string c_EventSource = "TaskVision";
		private const string c_LogName = "Application";

		public static void Write(string errorMessage)
		{
			try
			{
				// the event source should be created during the installation process
				if (EventLog.SourceExists(c_EventSource))
				{
					// write the message as an error
					EventLog msg = new EventLog(c_LogName);
					msg.Source = c_EventSource;
					msg.WriteEntry(errorMessage, EventLogEntryType.Error);
				}
				else
				{
					// try to create the event source for the next error (this requires admin rights)
					EventLog.CreateEventSource(c_EventSource, c_LogName);
				}
			}
			catch
			{}
		}

        public static void WriteToFile(string txt, string FileName)
        {
            try
            {
                StreamWriter sw = new StreamWriter(FileName);
                sw.WriteLine(txt);
                sw.Flush();
                sw.Close();
            }
            catch (Exception ex)
            {
                HebMessageBox.Show(ex.Message);
            }
        }


	}
}
